<?php
/**
 * Created by PhpStorm.
 * User: xuzhong
 * Date: 2025/4/1
 * Time: 16:26
 */
namespace app\api\controller;
use think\Request;
use app\facade\Basic;
use  app\api\traits\ValidateTrait;
use think\exception\ValidateException;
class MinerPool extends BaseController
{
    use ValidateTrait; // 使用 Trait
    ##员工信息
    protected $request;
    protected $service;
    protected $operator_id;
    protected $validationScenes  = [
        'index'=>[
//            'pageIndex'=>['require|integer', 'staff.pageIndex'],
//            'pageSize'  => [['require', 'between:1,100'], 'staff.pageSize'],
            'currency_ids' =>[['require'], 'minerpool.currency_id'],
        ],
        'manualbook'=>[
//            'pageIndex'=>['require|integer', 'staff.pageIndex'],
//            'pageSize'  => [['require', 'between:1,100'], 'staff.pageSize'],
            'sku_id' =>[['require'], 'manualbook.sku_id'],
        ],
        'detail'=>[
            'id'=>['require', 'id'],

        ]

    ];

    public function __construct(Request $request)
    {
        $this->request = $request;
        $this->service = new \app\api\service\MinerPool();

    }

    /**
     * @describe 获取矿池列表
     * @author: xuzhong
     * @date: 2025-04-17 16:04:33
     * @param [] type
     * @return Renderable
     */
    public function index()
    {
        $params = $this->request->all();
        try {
            $this->autoValidate('index');
            // 验证通过逻辑...
        } catch (ValidateException $e) {
            // 错误处理...
            $customErrors = $e->getMessage()??'';
            return Basic::json(['code'=>100001, 'message'=>$customErrors ]);
        }
        $res = $this->service->getList($params);

        return Basic::json($res);
    }

    /*
     *
     * 通过sku获取矿池
     * */
    public function getListBySku()
    {
        $params = $this->request->all();
        try {
            $this->autoValidate('manualbook');
            // 验证通过逻辑...
        } catch (ValidateException $e) {
            // 错误处理...
            $customErrors = $e->getMessage()??'';
            return Basic::json(['code'=>100001, 'message'=>$customErrors ]);
        }
        $res = $this->service->getListBySku($params);

        return Basic::json($res);
    }

}